<template>
  <!-- 猜你喜欢 -->
  <view class="caption">
    <image src="@/static/images/bubble.png" mode="aspectFit"></image>
    <text class="text"> 猜你喜欢 </text>
    <image src="@/static/images/bubble.png" mode="aspectFit"></image>
  </view>
  <view class="guess">
    <view class="guess-item" v-for="item in list" :key="item.id">
      <view class="guess-item__img">
        <image :src="item.picture" mode="aspectFit"></image>
      </view>
      <view class="guess-item__name">
        <text>{{ item.name }}</text>
      </view>
      <view class="guess-item__price">
        <text class="price">￥{{ item.price }}</text>
      </view>
    </view>
  </view>
  <view class="loading-text"> 正在加载... </view>
</template>

<script setup lang="ts">
import type { GuessItem } from "@/types/index";
import { toRefs } from "vue";
const props = defineProps<{
  list: GuessItem[];
}>();

// 简化模板中的引用
const { list } = toRefs(props);

// 添加组件对象以便外部使用
defineExpose({
  // 可以在这里添加需要暴露的方法或属性
});
</script>

<style lang="scss" scoped>
.caption {
  margin: 40rpx 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 30rpx;

  image {
    width: 20rpx;
    height: 20rpx;
  }
}

.guess {
  display: flex;
  flex-wrap: wrap;
  margin: 0 20rpx;
  gap: 15rpx;

  .guess-item {
    flex: 1;
    min-width: 250rpx;
    background-color: #fff;
    padding: 15rpx;
    display: flex;
    flex-direction: column;
    gap: 20rpx;
    min-height: 480rpx;
    border-radius: 10rpx;

    .guess-item__img {
      height: 300rpx;

      image {
        width: 100%;
        height: 100%;
      }
    }

    .guess-item__name {
      height: 80rpx;
      overflow: hidden;
      text-overflow: ellipsis;
      line-clamp: 2;
      -webkit-line-clamp: 2;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }

    .guess-item__price {
      .price {
        color: red;
      }
    }
  }
}

.loading-text {
  text-align: center;
  margin: 15rpx 0;
}
::v-deep .uni-image {
  width: 100% !important;
  height: 100% !important;
}
</style>
